<template>
	<view class="content">
		<view class="list-block">
			<template v-if="list.length>0">
				<view class="entrepreneurship-item" :style="style" v-for="item in list"
					@click="navigate('/page_pack/entrepreneurship/village?id='+item.id+'&type=2')">
					<!-- <image :src="item.coverImage" mode="aspectFill" class="entrepreneurship-cover"></image> -->
					<view class="entrepreneurship-info">
						<view class="title">{{item.title}}</view>
						<view class="address">
							发布时间：{{item.createTime.slice(0,-8)}}
						</view>
					</view>
				</view>
			</template>
			<view v-if="more==false&&list.length==0" class="empty">暂无数据</view>
			<view v-else-if="more==false&&list.length>0" class="empty">没有更多了</view>
		</view>
	</view>
</template>

<script>
	import {
		isMore
	} from '@/util/util'
	import {
		getMerchants
	} from '@/api/article';
	export default {
		data() {
			return {
				conf: {
					page: 1,
					limit: 20,
				},
				more: true,
				list: [],
				tabActive: 0
			}
		},
		methods: {
			bindActive(index) {
				this.tabActive = index
				this.getList(true)
			},
			handleRefresh() {
				this.conf.page = 1;
				this.more = true
				this.getList(true)
			},
			getList(refresh = false) {
				uni.showLoading({
					title: '加载中',
					mask: true
				})
				getMerchants(this.conf).then(res => {
					let list = res.list || [];
					if (refresh) {
						this.list = list;
					} else {
						this.list = [...this.list, ...list]
					}
					this.more = isMore(this.conf.page, this.conf.limit, res.count);
				}).finally(() => {
					uni.stopPullDownRefresh();
				})
			}
		},
		onPullDownRefresh() {
			this.handleRefresh();
		},
		onReachBottom() {
			if (this.more) {
				this.conf.page++;
				this.getList();
			}
		},
		onLoad() {
			this.getList(true)
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		min-height: 100vh;

		.list-block {
			width: 100%;
			padding: 30rpx;

			.entrepreneurship-item {
				width: 100%;
				height: 220rpx;
				border-radius: 8px;
				background: #fff;
				display: flex;
				align-items: center;
				padding: 30rpx;
				margin-bottom: 20rpx;

				.entrepreneurship-cover {
					width: 160rpx;
					height: 160rpx;
					border-radius: 8px;
					margin-right: 20rpx;
					background-color: #f5f5f5;
				}

				.entrepreneurship-info {
					width: 100%;
					height: 100%;
					display: flex;
					flex-direction: column;
					justify-content: center;
					position: relative;

					.status {
						position: absolute;
						right: 0;
						bottom: 0;
					}

					.title {
						width: 100%;
						font-weight: bold;
						word-break: break-all;
						text-overflow: ellipsis;
						display: -webkit-box;
						-webkit-box-orient: vertical;
						-webkit-line-clamp: 2;
						/* 超出几行省略 */
						overflow: hidden;
						font-size: 34rpx;
						font-weight: bold;
						margin-bottom: 30rpx;
					}

					.address {
						font-size: 28rpx;
						width: 100%;
						white-space: nowrap;
						overflow: hidden;
						text-overflow: ellipsis;
						color: #999;
					}
				}
			}
		}
	}
</style>